Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
replace document.getElementbyId("id") with just id

It seems that this code is working well. Please try it out before you answer:

    <!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p>In this example, x, y, and z are variables.</p>
<p id="demo"></p>
<script>
let x = 7;
let y = 45;
let z = x + y;
demo.innerHTML = "The value of z is: " + z;//please note this line
</script>
</body>
</html>

Does this mean that I can replace document.getElementById("id"). with just id.???

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It's working but it's considered legacy and unsafe.

about 4 years ago · Juan Pablo Isaza Report

0

Seems like it does, and it works for nested elements also... I wonder though if it works on a different js file imported from the html.

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p>In this example, x, y, and z are variables.</p>
<p id="demo1">
  <p id="demo2"></p>
</p>
<p id="demo"></p>
<script>
let x = 7;
let y = 45;
let z = x + y;
demo.innerHTML = "The value of z is: " + z;//please note this line

demo2.innerHTML = "The value of z is: " + z;//please note this line
console.log(demo);
</script>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!